package main

import (
	"fmt"
	"github.com/jessevdk/go-flags"
)

type Option struct {
	Verbose []bool `short:"v" long:"verbose" description:"Show verbose debug message"`
}

type OptionGloable struct {
	IntFlag        int            `short:"i" long:"int" description:"int flag value"`
	IntSlice       []int          `long:"intslice" description:"int slice flag value"`
	BoolFlag       bool           `long:"bool" description:"bool flag value"`
	BoolSlice      []bool         `long:"boolslice" description:"bool slice flag value"`
	FloatFlag      float64        `long:"float" description:"float64 flag value"`
	FloatSlice     []float64      `long:"floatslice" description:"float64 slice flag value"`
	StringFlag     string         `long:"string" short:"s" description:"string flag value"`
	StringSlice    []string       `long:"strslice" description:"string slice flag value"`
	PtrStringSlice []*string      `long:"pstrslice" description:"slice of pointer of str"`
	Call           func(string)   `long:"call" description:"callback"`
	IntMap         map[string]int `long:"intmap" description:"A map from string to int"`
}

// go build -gcflags="-m -m -l"
func main() {
	var opt Option
	flags.Parse(&opt)
	fmt.Println(opt.Verbose)

	{
		var optG OptionGloable
		optG.Call = func(s string) {
			fmt.Println("in callback:", s)
		}
		_, err := flags.Parse(&optG)
		if err != nil {
			fmt.Println("Parse error:", err)
			return
		}
		fmt.Printf("int flag: %v\n", optG.IntFlag)
		fmt.Printf("int slice flag: %v\n", optG.IntSlice)
		fmt.Printf("bool flag: %v\n", optG.BoolFlag)
		fmt.Printf("bool slice flag: %v\n", optG.BoolSlice)
		fmt.Printf("float flag: %v\n", optG.FloatFlag)
		fmt.Printf("float slice flag: %v\n", optG.FloatSlice)
		fmt.Printf("string flag: %v\n", optG.StringFlag)
		fmt.Printf("string slice flag: %v\n", optG.StringSlice)
		fmt.Println("slice of pointer of string flag: ")
		for i := 0; i < len(optG.PtrStringSlice); i++ {
			fmt.Printf("\t%d: %v\n", i, *optG.PtrStringSlice[i])
		}
		fmt.Printf("intmap: %v\n", optG.IntMap)
	}
}
